package gdut.jmxywz.action;

import gdut.jmxywz.been.Bookmaking;
import gdut.jmxywz.been.Teacher;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.components.ActionMessage;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.inject.Context;

import gdut.jmxywz.been.Setmoney;
import gdut.jmxywz.util.PageModel;

/**
 * @说明 此方法用于分页查询
 * @param 不需要参数
 * @author 徐健泉，黄羽中（改）
 * */
public class SetMoneyAction extends BaseAction {

	private static final String TEACHER_SESSION_KEY = "teacherSessionKey";
	private Setmoney setmoney = new Setmoney();
	private String money;
	private String year;
	private String allyearmoney;
	private String whichyear;
	private String whichyearl;
	private String whichmuothl;
	private String yeartagt;
	private int teacherId;
	private Teacher teacher;
	private List<Teacher> teacherList= new ArrayList<Teacher>();;

	public List<Teacher> getTeacherList() {
		return teacherList;
	}

	public void setTeacherList(List<Teacher> teacherList) {
		this.teacherList = teacherList;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	private String thismonth;
	private int currentPage;
	private int pageSize;
	private PageModel pageModel;

	/*************** 增加或修改教师的金额设定 *****************/
	public void addorupdateMoney() throws Exception {

		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		setmoney.setTeacherId(teacher.getTeacherId());
		setmoney.setTeacherName(teacher.getTeacherName());
		Date now = new Date();
		SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
		String year2 = year1.format(now);
		System.out.println(year2);
		setmoney.setYear(year2);
		this.getCommonService().saveObject(setmoney);

	}

	/*************** 展示当前教师的每一月的金额设定(非管理员) *****************/
	public String show() throws Exception {

		String hql = null;

		Map request = (Map) ActionContext.getContext().get("request");
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		int teacherId1 = teacher.getTeacherId();
		if (null != year && !("".equals(year))) {
			hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
					+ "and year = '" + year + "'";
			List findmoney = this.getCommonService().findListByHql(hql, null);
			request.put("findmoney", findmoney);
		} else {
			Date now = new Date();
			SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
			String year2 = year1.format(now);
			hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
					+ "and year = '" + year2 + "'";
			List findmoney = this.getCommonService().findListByHql(hql, null);
			System.out.println(((Setmoney) findmoney.toArray()[0])
					.getTeacherId());
			if (null == findmoney)
				this.addorupdateMoney();

			Calendar ca = Calendar.getInstance();
			int month = ca.get(Calendar.MONTH);// 获取月份
			request.put("findmoney", findmoney);
			request.put("month", month);
		}
		return SUCCESS;
	}

	/**
	 * 展示当前教师的每一年每一月的金额设定(非管理员)（huangyuzhon新加）
	 * 
	 * @return
	 * @throws Exception
	 */
	public String showTeachereveryyearmoney() throws Exception {
		if (currentPage == 0)
			currentPage = 0;
		if (pageSize == 0)
			pageSize = 5;
	   
	  
		Map request = (Map) ActionContext.getContext().get("request");
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		int teacherId1 = teacher.getTeacherId();
		
		
		
		String hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
				+ "";
		if (null != year && !("".equals(year))){
			ActionContext.getContext().getSession().put("yearsession", year);
			hql = hql + "and year = '" + year + "'";
		 
		}
		
		hql = hql + " order by teacherId asc,teacherName asc";
		List all = this.getCommonService().findListByHql(hql, null);
		if(all.size()==0){
			request.put("pageModel", null);
		}else{
			request.put("pageModel", all);
		}
		
		return SUCCESS;
	}
	
	
	/**
	 * 展示当前教师的今年的金额设定(非管理员)（huangyuzhon新加）
	 * 
	 * @return
	 * @throws Exception
	 */
	public String showTeacherThisyearmoney() throws Exception {
		SimpleDateFormat format=new SimpleDateFormat("yyyy");
		String startyear=format.format(new Date());
		ActionContext.getContext().getSession().put("yearsession", startyear);
		if (currentPage == 0)
			currentPage = 0;
		if (pageSize == 0)
			pageSize = 5;
		Map request = (Map) ActionContext.getContext().get("request");
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		int teacherId1 = teacher.getTeacherId();
		
		Date now = new Date();
		SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
		String year2 = year1.format(now);
		String hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
				+ "and year = '" + year2 + "'";
		
		/*
		 * else{ Date now = new Date(); SimpleDateFormat year1 = new
		 * SimpleDateFormat("yyyy"); String year2 = year1.format(now); hql = hql
		 * + "and year = '" + year2 + "'"; }
		 */
		hql = hql + " order by teacherId asc,teacherName asc";
		List all = this.getCommonService().findListByHql(hql, null);
		request.put("pageModel", all);
		return SUCCESS;
	}
	

	/**
	 * 该方法是系统管理员查看所有老师的金额设定
	 * 
	 * @return
	 * @throws Exception
	 */
	public String showAll() throws Exception {

		if (currentPage == 0)
			currentPage = 0;
		if (pageSize == 0)
			pageSize = 5;
		Map request = (Map) ActionContext.getContext().get("request");

		String hql = " from Setmoney  where 1=1";
		if (null != year && !("".equals(year)))
			hql = hql + "and year = '" + year + "'";
		else {
			Date now = new Date();
			SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
			String year2 = year1.format(now);
			hql = hql + "and year = '" + year2 + "'";
		}
		hql = hql + " order by teacherId asc,teacherName asc";
		List all = this.getCommonService().findListByHql(hql, null);
		request.put("pageModel", all);
		return SUCCESS;

	}

	
	
	/* 更新财务设定信息 */
	public String update() throws Exception {
		System.out.println(money);
		String money1;
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		int teacherId1 = teacher.getTeacherId();
		String hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1;
		List findmoney = this.getCommonService().findListByHql(hql, null);
		Setmoney s = (Setmoney) findmoney.toArray()[0];
		System.out.println(money);
		if (null != money && !("".equals(money))) {

			money1 = money;
			System.out.println("*********3********");
			System.out.println(money1);
			System.out.println("***********34******");
			s.setJanuary(money1);
			s.setFebruary(money1);
			s.setApril(money1);
			s.setMarch(money1);
			s.setMay(money1);
			s.setJune(money1);
			s.setJuly(money1);
			s.setAugust(money1);
			s.setSeptember(money1);
			s.setOctober(money1);
			s.setNovember(money1);
			s.setDecember(money1);
		} else {
			if (null != setmoney.getJanuary()
					&& !("".equals(setmoney.getJanuary())))
				s.setJanuary(setmoney.getJanuary());
			if (null != setmoney.getFebruary()
					&& !("".equals(setmoney.getFebruary())))
				s.setFebruary(setmoney.getFebruary());
			if (null != setmoney.getApril()
					&& !("".equals(setmoney.getApril())))
				s.setApril(setmoney.getApril());
			if (null != setmoney.getMarch()
					&& !("".equals(setmoney.getMarch())))
				s.setMarch(setmoney.getMarch());
			if (null != setmoney.getMay() && !("".equals(setmoney.getMay())))
				s.setMay(setmoney.getMay());
			if (null != setmoney.getJune() && !("".equals(setmoney.getJune())))
				s.setJune(setmoney.getJune());
			if (null != setmoney.getJuly() && !("".equals(setmoney.getJuly())))
				s.setJuly(setmoney.getJuly());
			if (null != setmoney.getAugust()
					&& !("".equals(setmoney.getAugust())))
				s.setAugust(setmoney.getAugust());
			if (null != setmoney.getSeptember()
					&& !("".equals(setmoney.getSeptember())))
				s.setSeptember(setmoney.getSeptember());
			if (null != setmoney.getOctober()
					&& !("".equals(setmoney.getOctober())))
				s.setOctober(setmoney.getOctober());
			if (null != setmoney.getNovember()
					&& !("".equals(setmoney.getNovember())))
				s.setNovember(setmoney.getNovember());
			if (null != setmoney.getDecember()
					&& !("".equals(setmoney.getDecember())))
				s.setDecember(setmoney.getDecember());
		}

		boolean bool = this.getCommonService().updateObject(s);
		this.show();
		if (bool)
			return SUCCESS;
		else
			return ERROR;
	}

	/* 指定月份金额设定 */
	public String setThisMonth() throws Exception {
		ActionContext.getContext().getSession().put("queryyear", whichyearl);
		String money1;
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		int teacherId1 = teacher.getTeacherId();
		String hql="";
		if(!"".equals(whichyearl)&&whichyearl!=null){
			hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
			+ "and year = '" + whichyearl + "'";
		}else{
			
		
		Date now = new Date();
		SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
		String year2 = year1.format(now);
		 hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
				+ "and year = '" + year2 + "'";
		}
		
		//新加(3.7)
		String newhql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
		+ "and year = '" + whichyearl + "'";
		List theyearall = this.getCommonService().findListByHql(newhql, null);
		if(theyearall==null||theyearall.size()==0){			
			Setmoney s=new Setmoney();
			s.setYear(whichyearl);
			s.setTeacherId(teacher.getTeacherId());
			s.setTeacherName(teacher.getTeacherName());
			if (null != thismonth && !("".equals(thismonth))) {
				money1 = thismonth;
				System.out.println(money1);
				
				switch (Integer.parseInt(whichmuothl)-1) {
				case 0:
					
					s.setJanuary(money1);
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					
					break;
				case 1:
					s.setJanuary("0");
					s.setFebruary(money1);
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 2:
					
								s.setJanuary("0");
								s.setFebruary("0");
								s.setMarch(money1);
								s.setApril("0");
								s.setMay("0");
								s.setJune("0");
								s.setJuly("0");
								s.setAugust("0");
								s.setSeptember("0");
								s.setOctober("0");
								s.setNovember("0");
								s.setDecember("0");
								
					break;
				case 3:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril(money1);
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 4:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay(money1);
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 5:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune(money1);
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 6:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly(money1);
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 7:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust(money1);
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 8:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember(money1);
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 9:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober(money1);
					s.setNovember("0");
					s.setDecember("0");
					break;
				case 10:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember(money1);
					s.setDecember("0");
					break;
				case 11:
					s.setJanuary("0");
					s.setFebruary("0");
					s.setMarch("0");
					s.setApril("0");
					s.setMay("0");
					s.setJune("0");
					s.setJuly("0");
					s.setAugust("0");
					s.setSeptember("0");
					s.setOctober("0");
					s.setNovember("0");
					s.setDecember(money1);
					break;
				default:
					break;
				}
			}
			boolean bool = this.getCommonService().saveObject(s);
			
			this.show();
			if (bool)
				return SUCCESS;
			else
				return ERROR;
		}
		//
		
		List findmoney = this.getCommonService().findListByHql(hql, null);
		//
		/*if(findmoney==null||findmoney.size()==0){
			Setmoney s=new Setmoney();
			s.setYear(whichyearl);
			
		}*/
		//
		Setmoney s = (Setmoney) findmoney.toArray()[0];

		if (null != thismonth && !("".equals(thismonth))) {
			money1 = thismonth;
			System.out.println(money1);
			
			switch (Integer.parseInt(whichmuothl)-1) {
			case 0:
				
				s.setJanuary(money1);
			
				
				break;
			case 1:
				s.setFebruary(money1);
				break;
			case 2:
				
			    s.setMarch(money1);
				break;
			case 3:
				s.setApril(money1);
				break;
			case 4:
				s.setMay(money1);
				break;
			case 5:
				s.setJune(money1);
				break;
			case 6:
				s.setJuly(money1);
				break;
			case 7:
				s.setAugust(money1);
				break;
			case 8:
				s.setSeptember(money1);
				break;
			case 9:
				s.setOctober(money1);
				break;
			case 10:
				s.setNovember(money1);
				break;
			case 11:
				s.setDecember(money1);
				break;
			default:
				break;
			}
		}
		boolean bool = this.getCommonService().updateObject(s);
		
		this.show();
		if (bool)
			return SUCCESS;
		else
			return ERROR;

	}

	/**
	 * 一键设定全年教师金额
	 * 
	 * @return
	 * @throws Exceptoin
	 */
	public String setAllyearmoney() throws Exception {
		Teacher teacher = (Teacher) ActionContext.getContext().getSession()
				.get(TEACHER_SESSION_KEY);
		setmoney.setTeacherId(teacher.getTeacherId());
		int teacherId1 = teacher.getTeacherId();
		setmoney.setTeacherName(teacher.getTeacherName());
		Date now = new Date();
		SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
		String nowyear = year1.format(now);
		
		String hql = " from Setmoney  where 1=1 and teacherId = " + teacherId1
				+ "and year = '" + whichyear + "'";
		List isexsistfindmoney = this.getCommonService().findListByHql(hql,
				null);

		if ((Integer.parseInt(nowyear)>=Integer.parseInt(whichyear))) {
			ActionContext ctx1 = ActionContext.getContext();
			String tips = "";
			tips = "该年已经过去不能一键设定全年金额！若是本年请逐一修改未来每月的金额&nbsp;&nbsp; <button onclick='javascript:history.go(-1);'>返回上一页面</button>";
			ctx1.put("tip1", tips);
			return INPUT;
		} else if(isexsistfindmoney.size() > 0&&(Integer.parseInt(nowyear)<Integer.parseInt(whichyear))){
			List findmoney = this.getCommonService().findListByHql(hql, null);
			Setmoney s = (Setmoney) findmoney.toArray()[0];
			//this.getCommonService().findByStringId(id, Setmoney.class)
			s.setApril(allyearmoney);
			s.setAugust(allyearmoney);
			s.setDecember(allyearmoney);
			s.setFebruary(allyearmoney);
			s.setJanuary(allyearmoney);
			s.setJuly(allyearmoney);
			s.setJune(allyearmoney);
			s.setMarch(allyearmoney);
			s.setMay(allyearmoney);
			s.setNovember(allyearmoney);
			s.setOctober(allyearmoney);
			s.setSeptember(allyearmoney);
			this.getCommonService().updateObject(s);
			
			return SUCCESS;
		}else {
			setmoney.setApril(allyearmoney);
			setmoney.setAugust(allyearmoney);
			setmoney.setDecember(allyearmoney);
			setmoney.setFebruary(allyearmoney);
			setmoney.setJanuary(allyearmoney);
			setmoney.setJuly(allyearmoney);
			setmoney.setJune(allyearmoney);
			setmoney.setMarch(allyearmoney);
			setmoney.setMay(allyearmoney);
			setmoney.setNovember(allyearmoney);
			setmoney.setOctober(allyearmoney);
			setmoney.setSeptember(allyearmoney);
			setmoney.setYear(this.whichyear);
			this.getCommonService().saveObject(setmoney);
			return SUCCESS;
		}
	}

	/**
	 * 管理员导出excel(各年或今年)
	 * @throws Exception
	 */
	public void exportExcel() throws Exception {
		// TODO Auto-generated method stub
		/*导出EXCEL之前可以先查询记录，找到后再导出*/
		try{
			String[] str=new String[]{"姓名","年份","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
			List list;
			HttpServletResponse response=ServletActionContext.getResponse();
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setContentType("APPLICATION/OCTET-STREAM ");
			
			Date now = new Date();
			SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
			String nowyear = year1.format(now);
			
				String hql = "";
				
				
			if(yeartagt.equals("exportthisyear")){
				
				hql= " from Setmoney  where 1=1 and year = '" + nowyear + "'";
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("教师本年金额设定.xls","UTF-8"));
			}else if(yeartagt.equals("exportallyear")){
				
				hql="from Setmoney  where 1=1";
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode("教师各年金额设定.xls","UTF-8"));
			}
				
		    list=this.getCommonService().findListByHql(hql, null);
			
			
			if(list==null)return;

			
			WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
			WritableSheet sheet=wwb.createSheet("sheet1", 0);
			sheet.setColumnView(0, 20);
			sheet.setColumnView(1, 20);
			sheet.setColumnView(3, 20);
			sheet.setColumnView(4, 20);
			sheet.setColumnView(5, 20);
			sheet.setColumnView(6, 20);
			sheet.setColumnView(7, 20);
			sheet.setColumnView(8, 20);
			sheet.setColumnView(9, 20);
			sheet.setColumnView(10, 20);
			sheet.setColumnView(11, 20);
			sheet.setColumnView(12, 20);
			sheet.setColumnView(13, 20);
			sheet.setColumnView(14, 20);
			Label label=null;
			for(int i=0;i<str.length;i++){
				label=new Label(i,0,str[i]);
				sheet.addCell(label);
			}
			for(int i=0;i<list.size();i++){
				setmoney=(Setmoney)list.get(i);
				
				label=new Label(0,i+1,setmoney.getTeacherName());
				sheet.addCell(label);
				label=new Label(1,i+1,setmoney.getYear());
				sheet.addCell(label);
				label=new Label(2,i+1,setmoney.getJanuary()+"");
				sheet.addCell(label);
				label=new Label(3,i+1,setmoney.getFebruary()+"");
				sheet.addCell(label);
				label=new Label(4,i+1,setmoney.getMarch()+"");
				sheet.addCell(label);
				label=new Label(5,i+1,setmoney.getApril()+"");
				sheet.addCell(label);
				label=new Label(6,i+1,setmoney.getMay()+"");
				sheet.addCell(label);
				label=new Label(7,i+1,setmoney.getJune()+"");
				sheet.addCell(label);
				label=new Label(8,i+1,setmoney.getJuly()+"");
				sheet.addCell(label);
				label=new Label(9,i+1,setmoney.getAugust()+"");
				sheet.addCell(label);
				label=new Label(10,i+1,setmoney.getSeptember()+"");
				sheet.addCell(label);
				label=new Label(11,i+1,setmoney.getOctober()+"");
				sheet.addCell(label);
				label=new Label(12,i+1,setmoney.getNovember()+"");
				sheet.addCell(label);
				label=new Label(13,i+1,setmoney.getDecember()+"");
				sheet.addCell(label);
				
				
					label=new Label(14,i+1,"");
					sheet.addCell(label);
			
				
			}
			wwb.write();
			wwb.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	
	
	/**
	 * 教师导出个人的金额设定(今年或全部)
	 */
	public void personexportExcel() throws Exception {
		// TODO Auto-generated method stub
		/*导出EXCEL之前可以先查询记录，找到后再导出*/
		this.teacher = ((Teacher)ActionContext.getContext().getSession().get("teacherSessionKey"));
		try{
			String[] str=new String[]{"姓名","年份","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
			List list;
			HttpServletResponse response=ServletActionContext.getResponse();
			response.reset();
			response.setContentType("application/vnd.ms-excel");
			response.setContentType("APPLICATION/OCTET-STREAM ");
			
			Date now = new Date();
			SimpleDateFormat year1 = new SimpleDateFormat("yyyy");
			String nowyear = year1.format(now);
			
				String hql = "";
				
				
			if(yeartagt.equals("exportthisyear")){
				
				hql= " from Setmoney  where teacherName='"+this.teacher.getTeacherName()+"' and year = '" + nowyear + "'";
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode(this.teacher.getTeacherName()+"老师本年金额设定.xls","gb2312"));
			}else if(yeartagt.equals("exportallyear")){
				
				hql="from Setmoney  where teacherName='"+this.teacher.getTeacherName()+"'";
				response.setHeader("Content-Disposition","attachment; filename="+java.net.URLEncoder.encode(this.teacher.getTeacherName()+"老师各年金额设定.xls","gb2312"));
			}
				
		    list=this.getCommonService().findListByHql(hql, null);
			
			
			if(list==null)return;

			
			WritableWorkbook wwb=Workbook.createWorkbook(response.getOutputStream());
			WritableSheet sheet=wwb.createSheet("sheet1", 0);
			sheet.setColumnView(0, 20);
			sheet.setColumnView(1, 20);
			sheet.setColumnView(3, 20);
			sheet.setColumnView(4, 20);
			sheet.setColumnView(5, 20);
			sheet.setColumnView(6, 20);
			sheet.setColumnView(7, 20);
			sheet.setColumnView(8, 20);
			sheet.setColumnView(9, 20);
			sheet.setColumnView(10, 20);
			sheet.setColumnView(11, 20);
			sheet.setColumnView(12, 20);
			sheet.setColumnView(13, 20);
			sheet.setColumnView(14, 20);
			Label label=null;
			for(int i=0;i<str.length;i++){
				label=new Label(i,0,str[i]);
				sheet.addCell(label);
			}
			for(int i=0;i<list.size();i++){
				setmoney=(Setmoney)list.get(i);
				
				label=new Label(0,i+1,setmoney.getTeacherName());
				sheet.addCell(label);
				label=new Label(1,i+1,setmoney.getYear());
				sheet.addCell(label);
				label=new Label(2,i+1,setmoney.getJanuary()+"");
				sheet.addCell(label);
				label=new Label(3,i+1,setmoney.getFebruary()+"");
				sheet.addCell(label);
				label=new Label(4,i+1,setmoney.getMarch()+"");
				sheet.addCell(label);
				label=new Label(5,i+1,setmoney.getApril()+"");
				sheet.addCell(label);
				label=new Label(6,i+1,setmoney.getMay()+"");
				sheet.addCell(label);
				label=new Label(7,i+1,setmoney.getJune()+"");
				sheet.addCell(label);
				label=new Label(8,i+1,setmoney.getJuly()+"");
				sheet.addCell(label);
				label=new Label(9,i+1,setmoney.getAugust()+"");
				sheet.addCell(label);
				label=new Label(10,i+1,setmoney.getSeptember()+"");
				sheet.addCell(label);
				label=new Label(11,i+1,setmoney.getOctober()+"");
				sheet.addCell(label);
				label=new Label(12,i+1,setmoney.getNovember()+"");
				sheet.addCell(label);
				label=new Label(13,i+1,setmoney.getDecember()+"");
				sheet.addCell(label);
				
				
					label=new Label(14,i+1,"");
					sheet.addCell(label);
			
				
			}
			wwb.write();
			wwb.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 跳转到薪酬录入
	 * @return
	 */
	public String enterpament() throws Exception{
		
		String hql="from Teacher t order by t.teacherId desc";
		teacherList=this.getCommonService().findListByHql(hql, null);
		
		return SUCCESS;
		
	}

	public Setmoney getSetmoney() {
		return setmoney;
	}

	public void setSetmoney(Setmoney setmoney) {
		this.setmoney = setmoney;
	}

	public String getMoney() {
		return money;
	}

	public void setMoney(String money) {
		this.money = money;
	}

	public int getTeacherId() {
		return teacherId;
	}

	public void setTeacherId(int teacherId) {
		this.teacherId = teacherId;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public static String getTeacherSessionKey() {
		return TEACHER_SESSION_KEY;
	}

	public String getThismonth() {
		return thismonth;
	}

	public void setThismonth(String thismonth) {
		this.thismonth = thismonth;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public PageModel getPageModel() {
		return pageModel;
	}

	public void setPageModel(PageModel pageModel) {
		this.pageModel = pageModel;
	}

	public String getAllyearmoney() {
		return allyearmoney;
	}

	public void setAllyearmoney(String allyearmoney) {
		this.allyearmoney = allyearmoney;
	}

	public String getWhichyear() {
		return whichyear;
	}

	public void setWhichyear(String whichyear) {
		this.whichyear = whichyear;
	}

	public String getYeartagt() {
		return yeartagt;
	}

	public void setYeartagt(String yeartagt) {
		this.yeartagt = yeartagt;
	}

	public String getWhichmuothl() {
		return whichmuothl;
	}

	public void setWhichmuothl(String whichmuothl) {
		this.whichmuothl = whichmuothl;
	}

	public String getWhichyearl() {
		return whichyearl;
	}

	public void setWhichyearl(String whichyearl) {
		this.whichyearl = whichyearl;
	}

}
